﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMA.GENTEv1.Dados;

namespace SMA.GENTEv1
{
    public class Status
    {
        #region Variaveis Membro
        private int _idStatus;
        private string _descricao;
        private GENTEEntities _context;
        #endregion  

        #region Parametros
        public int IdStatus
        {
            get { return _idStatus; }
            set { _idStatus = value; }
        }
        public string Descricao
        {
            get { return _descricao; }
            set { _descricao = value; }
        }
        #endregion

        #region Construtores
        public Status()
        {
            try
            {
                _context = new GENTEEntities();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public Status(int idStatus)
        {
            try
            {
                _context = new GENTEEntities();
                Carregar(idStatus);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Metodos Privados
        private void Carregar(int idStatus)
        {
            try
            {
                var consulta = from s in _context.tab_status
                               where s.id_status == idStatus
                               select s;

                var listConsulta = consulta.ToList();

                foreach (var list in listConsulta)
                {
                    this._idStatus = list.id_status;
                    this._descricao = list.descricao;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Metodos Publicos
        public List<Status> SelectAll()
        {
            try
            {
                List<Status> listStatus = new List<Status>();

                var consulta = from s in _context.tab_status
                               select s;

                var listConsulta = consulta.ToList();

                foreach (var list in listConsulta)
                {
                    Status status = new Status();
                    status.IdStatus = list.id_status;
                    status.Descricao = list.descricao;

                    listStatus.Add(status);
                }

                return listStatus;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public int[] ObterCodigosStatus(List<Status> status)
        {
            int[] _codigos = new int[status.Count];
            int _cont = 0;

            foreach (Status item in status)
            {
                _codigos[_cont] = item.IdStatus;
                _cont++;
            }

            return _codigos;
        }
        #endregion
    }
}
